package interFace;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

public class MyServiceImpl implements MyService {

    @Override
    public void execute() {
        System.out.println("MyServiceImpl execute");
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        //使用了Java标准库中的ServiceLoader类，用于加载实现了指定服务接口的提供者（Provider）。
        ServiceLoader<MyService> serviceLoader = ServiceLoader.load(MyService.class);
        for(MyService service: serviceLoader) {
            service.execute();
        }
        List<String> stringList = new ArrayList<>();
        stringList.add("yes");
        stringList.add("no");
        stringList.getClass().getMethod("add", Object.class).invoke(stringList,123);
        System.out.println(stringList);
    }
}
